package com.esheeper.logictimestampprovider.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Stack;

@Service
public class ValidatorUtil {

    @Value("crypt.md5.logic-timestamp-provider-validate-salt")
    private static String salt;
    public static Boolean validateToken(String token,String randomString) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update((randomString+salt).getBytes());
        String hashedPwd = new BigInteger(1, md5.digest()).toString(16);
        System.out.println(hashedPwd);
        Base64.Encoder encoder = Base64.getEncoder();
        if (encoder.encodeToString(md5.digest()) != randomString){
            return false;
        }
        return true;
    }
}
